<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>循环</title>
  <style>
    .box {
      width: 100px;
      height: 100px;
      line-height: 100px;
      border: 1px solid #000;
      display: inline-block;
      text-align: center;
    }
    .box:hover {
      background-color: #ddd;
    }
  </style>
</head>
<body>
  <div>
    <div class="box">1</div>
    <div class="box">2</div>
    <div class="box">3</div>
    <div class="box">4</div>
  </div>
</body>


<script>
  var arr = [1, 2, 3, 4]
  // console.log(arr[0]);
  // console.log(arr[1]);
  // console.log(arr[2]);
  // console.log(arr[3]);
  
  // for (var i = 0; i < arr.length; i++) {
  //   console.log(arr[i]);
  // }

  // var i = 0
  // while (i < arr.length) {
  //   console.log(arr[i]);
  //   i++;
  // }

  // 只打印奇数
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] % 2 === 0) {
      continue // 跳过
    }
    console.log(arr[i]);
  }

  // 遇到2就跳出循环
  for (var i = 0; i < arr.length; i++) {
    if (arr[i] === 2) {
      break;
    }
    console.log(arr[i]);
  }
</script>
</html>